/**
 * @Description: 超图地图
 * @Author: xubaoliang
 * @Date: 2022-01-25 09:19:27
 */
import TileLayer from "ol/layer/Tile";
import {TileSuperMapRest} from "@supermap/iclient-ol";
import '@supermap/iclient-ol/css/index';
import {Map, View} from "ol";

import globalConfigs from '@/utils/globalConfigs';

let SuperMap = {
  /**
   * 初始化百度地图
   * @param elId
   * @param configs
   * @param options
   * @return {Map}
   */
  init: function (elId, configs, options) {
    let mapLayer = new TileLayer({
      id: 'baseLayer',
      source:  new TileSuperMapRest({
        url: globalConfigs.MAPSETTINGS.MAPTILEURL,
        projection: 'EPSG:4326',
        crossOrigin: 'anonymous',
      }),
      projection: 'EPSG:4326',
    });
    let mapApp = new Map({
      target: elId,
      layers: [mapLayer],
      view: new View({
        projection: "EPSG:4326",    //使用这个坐标系
        center: options.center || configs.mapCenter,
        zoom: options.zoom || configs.defaultZoom,
        minZoom: options.minZoom || configs.minZoom,
        maxZoom: options.maxZoom || configs.maxZoom,
        // 设置缩放级别为整数
        constrainResolution: true,
        // 关闭无级别缩放地图
        smoothResolutionConstraint: false
      }),
      controls: []
    });
    return mapApp;
  }
}

export default SuperMap;
